<template>
    <view class="login-page bgDefault">
		
		<view class="top-backgroup tn-text-bold">
			<view class="login001 font26">Hi~</view>
			<view class="login002 font26 tn-color-white">欢迎来到<span>布芒的家</span></view>
			<view class="font26 tn-color-white login003" >现在登录！</view>
		</view>
		<view class="login004 tn-text-center">社区一公里社群生活家</view>
			
		<!-- 授权登录按钮 -->
		<!-- <view class="submit-btn"  @tap.stop="openAuthorizationModal"> -->
		<view class="submit-btn"  @tap="toLogin">
			<i class="tn-icon-wechat-fill"></i>
		  微信登录
		</view>
		
		<view class="login005 tn-text-center">
			<tn-checkbox v-model="checked" :labelSize="22" :size="24"></tn-checkbox>
			<view @tap="showPrivacyF">我已阅读并同意《布芒的家小程序隐私保护指引》</view>
		</view>
		
		<!-- 隐私协议 -->  
		<!-- #ifdef MP-WEIXIN -->
		<!-- 默认显示在中间 -->
		<privacy-popup ref="privacyComponent" @agree-privacy="agreePrivacy" :showPrivacy="showPrivacy"></privacy-popup> 
		<!-- #endif -->

    </view>
</template>

<script>
  import privacyPopup from '@/pages/components/privacy-popup/privacy-popup.vue'
  import {login,uploadUrl} from '@/api/user/login.js'
  import store from '@/store/index.js'
    export default {
    components: {privacyPopup },
        data() {
            return {
				checked:false,
				showPrivacy:false,
				backUrl :"/pages/index/index?index=4"
            }
        },
        onLoad(e) {
		
			if(e.resetToken){
				store.commit('$tStore', {
				  name: 'vuex_user',
				  value: {}
				})
			}
			var token = store.state?.vuex_user?.token || ""
			if(token) uni.navigateBack()
			
			if(e.backUrl){
				this.backUrl = decodeURIComponent(e.backUrl)
			}
        },
        methods: {
			agreePrivacy(){
				this.showPrivacy = false
				this.checked = true
			},
			showPrivacyF(){
				this.showPrivacy = true
			},
		  // 打开获取用户信息弹框
		  openAuthorizationModal() {
			this.showAuthorizationModal = true
		  },
		  toLogin(){
			var _url = this.backUrl
			
			uni.login({
			  provider: 'weixin', //使用微信登录
			  success: function (loginRes) {
			    if (loginRes.code) {
					
					loginRes.pid  = uni.getStorageSync("pid") || 0;
					login(loginRes).then(res=>{
						store.commit('$tStore', {
						  name: 'vuex_user',
						  value: res
						})
						uni.navigateTo({
						  url: _url
						})
					})
				} else {
					uni.showToast({
						icon: 'none',
						title: '授权失败'
					})
				}
			
			  },
			  fail:function(res){
				  console.log("#CCCCCC")
				  console.log(res)
			  }
			}); 
		  },

		  // 获取到的用户信息
		  updatedUserInfoEvent(info) {
			console.log('获取到的用户信息', info)
			uni.uploadFile({
				url:uploadUrl,
				filePath:info.avatar,
				name:"image",
				success:(res)=> {
					var data = JSON.parse(res.data)
					
					if(res.statusCode != 200 || data.code !=200){
						uni.showToast({
							icon: 'none',
							title: '图片上传失败 ' + res.errMsg
						})
						return false
					}
					info.avatar = data.data.url
					
					
					
				}
			})
			
			
		  },
        }
    }
</script>

<style lang="scss" scoped>
	.font26{
		font-size: 53rpx;
		span{
			color: $tn-main-orange;
		}
	}
    .login-page {
    width: 100vw;
    height: 100vh;
    /* display: flex; */
    align-items: center;
    justify-content: center;
	font-family: "PingFangSCRegular", sans-serif;
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
	letter-spacing: 1px;
  }
  .login001{
	color: $tn-main-orange;
	font-weight: bold;
  }
  .login002{font-size: 43rpx;
  font-family: "黑体", "Heiti SC", "STHeiti", sans-serif;
  }
  .login003{font-size: 36rpx;margin-top: 70rpx;}
  .login004{font-size: 36rpx;margin-top: 30rpx;color: $tn-main-orange;}
  .login005{
	  font-size: 16rpx;
	  margin-top: 30rpx;
	  display: flex;
	  justify-content: center;
	  .tn-checkbox{
		&.label{
			font-size: 16rpx;
		}
	  }
  }

  /* 授权按钮 */
  .submit-btn {
    width: 100%;
    background-color: $tn-main-orange;
    color: #FFFFFF;
    border-radius: 40rpx;
    padding: 25rpx;
    font-size: 28rpx;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 160rpx;
	i{
		    font-size: 18px;
		    color: #fff;
	}
  }
  
  .bgDefault{
  	  //background: linear-gradient(to right, #ccfed8, #b5e1e8), linear-gradient(to bottom, #ccfed8, #93b8fd);
  	background: $tn-main-bg;
  	 padding: 0 8%;
  }
  
  /* 顶部背景图 start */
  .top-backgroup {
    height: 48vh;
	padding-top: 227rpx;
    z-index: -1;
  
    background: url("/static/images/logo.png") center bottom  no-repeat;
  	background-size:50%
  }
</style>